package com.hee.erp.modules.controller;


import com.alibaba.fastjson.JSONObject;
import com.hee.erp.common.R;
import com.hee.erp.filter.LoginContextHolder;
import com.hee.erp.modules.entity.SysRight;
import com.hee.erp.modules.service.ISysRightService;
import com.hee.erp.modules.service.ISysUser2RightService;
import com.hee.erp.pojo.SysRightTreeNode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author weizehong
 * @since 2022-03-04
 */
@RestController
@RequestMapping("/modules/sysUser2Right")
@Api(tags = "SysUser2Right",produces = "application/json")
public class SysUser2RightController {

    @Autowired
    ISysRightService sysRightService;

    @Autowired
    ISysUser2RightService sysUser2RightService;

    @GetMapping("/getRightsTreeNodes")
    @ApiOperation(value = "getRightsTreeNodes",notes = "这里是参数说明")
    public R<List<SysRightTreeNode>> getRightsTreeNodes(){
        List<SysRightTreeNode> list = sysUser2RightService.getRightsByUserId(LoginContextHolder.get().getUserId());
        return R.success(list);
    }

    /**
     * 根据routePath查找按钮权限
     * @param params
     * @return
     */
    @PostMapping("/getBtnRightsByRoutePath")
    @ApiOperation(value = "getBtnRightsByRoutePath",notes = "这里是参数说明")
    public R<List<String>> getBtnRightsByRoutePath(@RequestBody JSONObject params){
        String routePath = params.getString("routePath");
        List<String> list = sysUser2RightService.getBtnRightsByRoutePath(routePath);
        return R.success(list);
    }

    @GetMapping("/getBigMenuByUserId")
    @ApiOperation("getBigMenuByUserId")
    public R<List<SysRight>> getBigMenuByUserId(String userId){
        List<SysRight> list = this.sysUser2RightService.getBigMenuByUserId(userId);
        return R.success(list);
    }

    @GetMapping("/getShortcutMenuByUserId")
    @ApiOperation("getShortcutMenuByUserId")
    public R<List<SysRight>> getShortcutMenuByUserId(String userId){
        List<SysRight> list = this.sysUser2RightService.getShortcutMenuByUserId(userId);
        return R.success(list);
    }

    @GetMapping("/getMenusByParentIdAndUserId")
    @ApiOperation("getMenusByParentIdAndUserId")
    public R<List<SysRight>> getMenusByParentIdAndUserId(String userId,String parentId){
        List<SysRight> list = this.sysUser2RightService.getMenusByParentIdAndUserId(userId,parentId);
        return R.success(list);
    }

    @PostMapping("/sort")
    @ApiOperation("sort")
    public R<Boolean> sort(@RequestBody List<String> ids){
        this.sysUser2RightService.sort(ids);
        return R.success(true);
    }

    @PostMapping("/setShortcut")
    @ApiOperation("setShortcut")
    public R<Boolean> setShortcut(@RequestBody List<String> ids){
        this.sysUser2RightService.setShortcut(ids);
        return R.success(true);
    }

    @GetMapping("/cancelShortcut")
    @ApiOperation("cancelShortcut")
    public R<Boolean> cancelShortcut(String rightId){
        this.sysUser2RightService.cancelShortcut(rightId);
        return R.success(true);
    }


}

